import render_content from "../../../lib/render_content.mjs";
import datarover from "../../../lib/datarover.mjs";

/**
 * 渲染数字格式
 * @param {HTMLElement} td - 单元格元素
 * @param {Object} col - 列配置
 */
export function renderNumber(td, col) {
  let value = datarover(td, col.col);
  if (!value && value !== 0) return;

  if (Number.isNaN(value)) {
    td.innerText = value;
    return;
  }

  let options = {};
  for (let key in col.NumberFormat) {
    options[key] =
      typeof col.NumberFormat[key] === "string"
        ? render_content(td, col.NumberFormat[key])
        : col.NumberFormat[key];
  }
  td.innerText = new Intl.NumberFormat("en-US", options).format(value);
}
